using System;
using System.IO;
using System.Collections.Generic;
using System.Diagnostics;


namespace Bechamel
{
    class Program
    {
        static void Main(string[] args)
        {
			Stopwatch sw = null;
			StringInput input;
			if (args.Length == 0) {
				Console.Write("scheme> ");
				string code = Console.ReadLine();
				input = new StringInput(code);
			} else {
				string code = File.ReadAllText(args[0]);
				input = new StringInput(code);
			}
			Console.WriteLine();

			Starter starter = new Starter();
			IronyParser parser = new IronyParser();
			IronyToExpressionFilter filter = new IronyToExpressionFilter();
			DlrExecutor executor = new DlrExecutor();

			starter.OutputChannel += input.InputChannel;
			input.OutputChannel += parser.InputChannel;
			parser.OutputChannel += filter.InputChannel;
			filter.OutputChannel += executor.InputChannel;
			executor.OutputChannel += delegate(object sender, OutputChannelEventArgs<string> e) {
				sw.Stop();
				Console.WriteLine();
				Console.WriteLine();
				Console.WriteLine(e.Data);
				Console.WriteLine("Script executed in " + sw.Elapsed.ToString());
			};

			sw = Stopwatch.StartNew();
			starter.StartMegaReaction();
        }
    }
}
